<style>
    .el-input__inner {
        height: 30px !important;
    }

    .layui-form .el-cascader {
        line-height: 30px;
        ;
    }
</style>
<div class="rc-pagepadding ">
    <div class=" rc-pannel rc-pagepadding">
        <div class="rc-pannel-body layui-form ">
            <form class="layui-form " method="get">
                <div class="rc-flex-vertical-center rc-searchbox">
                    <div class="layui-inline ">
                        <label class="layui-form-label">选择事件</label>
                        <div class="layui-input-inline " style="width: 400px;">
                            <input type="text" name="event_method_id" id="event_method_id" placeholder="" value="" autocomplete="off" class="layui-input">
                        </div>
                    </div>



                    <div class="layui-inline">
                        <div class="layui-form-label">
                            <button type="button" lay-submit lay-filter="submit" class="layui-btn layui-btn-sm layui-btn-primary"><i class="iconfont">&#xeafe;</i> 添加</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class=" rc-pannel rc-pagepadding rc-margin-top-default ">
        <div class="rc-pannel-body layui-form ">

            <table class="layui-table">
                <colgroup>
                    <col>
                    <col style="width: 140xp;">
                </colgroup>
                <thead>
                    <tr>

                        <th>事件</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>

                    <?php foreach ($hookevents as $key => $hookevent) { ?>
                        <tr>

                            <td><?php echo $hookevent['eventinfo']['title'] ?> / <?php echo $hookevent['eventmethodinfo']['title'] ?></td>
                            <td>
                                <div class="rc-opbar" style="">

                                    <a hookeventid="<?php echo $hookevent['id'] ?>" class="error delete" href="javascript:;"> <i class="iconfont">&#xe607;</i> 删除</a>
                                </div>
                            </td>
                        </tr>
                    <?php } ?>

                </tbody>
            </table>

        </div>
    </div>

</div>


<script src="/static/admin/lib/layui/modules/cascader/cascader.js"></script>
<script>
    layui.use(function() {
        var form = layui.form;
        var layer = layui.layer;

        var layCascader = layui.layCascader;

        var el_events = '<?php echo $events ?>';
        var el_events_obj = $.parseJSON(el_events);
        var el_cascader = layCascader({
            elem: '#event_method_id',
            filterable: true,
            options: el_events_obj,
            props: {
                value: 'cascaderid',
                label: 'title',
            },

        });

        $('.delete').click(function() {
            var hookeventid = $(this).attr('hookeventid');
            layer.confirm('确定要删除么？', {
                icon: 3
            }, function() {
                $.ajax({
                    url: '/admin/cnf/Hook/deleteEvent?id=' + hookeventid, //请求路径
                    type: "POST", //请求方式
                    success: function(data) {
                        if (data.code == 0) {
                            window.location.reload();
                        } else {
                            toastr_error(data.message);
                        }
                        layer.closeAll();
                    },
                    error: function() {
                        layer.closeAll();
                    },

                });


            }, function() {



            });
        })

        form.on('submit(submit)', function(data) {
            $.ajax({
                url: '/admin/cnf/Hook/triggerEvent', //请求路径
                type: "POST", //请求方式
                data: {
                    hookid: '<?php echo request()->get('hookid') ?>',
                    event_method_id: data.field.event_method_id,
                }, // 默认写法
                success: function(data) {
                    if (data.code == 0) {

                        window.location.reload();
                    } else {
                        toastr_error(data.message);
                    }
                },
                error: function() {

                },

            });
        });

    });
</script>